#include "trace.h"

FILE *trace_fp = NULL;
char record[80];
volatile bool need_record = false;

void init_trace() {
    trace_fp = fopen("trace.txt", "w");
    Assert(trace_fp, "Can not open 'trace.txt'");
}

void buf_record(uint32_t pc, int reg_no, uint32_t data) {
    sprintf(record, "0x%08x\t%d\t0x%08x", pc, reg_no, data);
    need_record = true;
}

void write_record() {
    printf("Write trace:[%s]\n", record);
    fprintf(trace_fp, "%s\n", record);
    need_record = false;
}